package com.adaxi.adc.business.vehicletrip.config;

import com.adaxi.adc.business.vehicletrip.filter.GateWayWallIntercepter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 涛哥
 * @version 1.0
 */
@EnableWebMvc
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {


    final
    GateWayWallIntercepter gateWayWallIntercepter;
    @Value("${my.uploadFilePath}")
    String filepath;

    public SpringMvcConfig(GateWayWallIntercepter gateWayWallIntercepter) {
        this.gateWayWallIntercepter = gateWayWallIntercepter;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations(
                        "classpath:/static/", "file:/" + filepath);
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations(
                        "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations(
                        "classpath:/META-INF/resources/webjars/");
    }


    /**
     * 添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(gateWayWallIntercepter)
                .addPathPatterns("/**");

    }

}
